﻿<UserControl x:Class="uTorrentSL.Views.FeedView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             xmlns:cv="clr-namespace:uTorrentSL.Converters"
             mc:Ignorable="d"
             DataContext="{Binding FeedViewModel, Source={StaticResource Locator}}">
    <UserControl.Resources>
        <Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
            <Setter Property="Padding" Value="3"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
        <cv:BooleanToVisibility x:Key="b2v"/>
    </UserControl.Resources>
    <Grid Grid.Row="1" Grid.Column="1" Margin="10,10,10,10">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <toolkit:DataForm CurrentItem="{Binding SelectedFeed, Mode=TwoWay}" AutoGenerateFields="False">
            <toolkit:DataForm.DataFieldStyle>
                <Style TargetType="toolkit:DataField">
                    <Setter Property="LabelPosition" Value="Top"/>
                    <Setter Property="VerticalAlignment" Value="Top"/>
                </Style>
            </toolkit:DataForm.DataFieldStyle>
            <toolkit:DataForm.EditTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="78"/>
                                <ColumnDefinition Width="78"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <toolkit:DataField PropertyPath="Enabled" Label="Enabled" >
                                <CheckBox IsChecked="{Binding Enabled}"/>
                            </toolkit:DataField>
                            <toolkit:DataField PropertyPath="Ident" Label="ID" Grid.Column="1">
                                <TextBox Text="{Binding Ident, Mode=TwoWay}"/>
                            </toolkit:DataField>
                            <toolkit:DataField PropertyPath="Alias" Label="Name" Grid.Column="2">
                                <TextBox Text="{Binding Alias, Mode=TwoWay}"/>
                            </toolkit:DataField>
                        </Grid>
                        <toolkit:DataField PropertyPath="Url" Label="Url">
                            <TextBox Text="{Binding Url, Mode=TwoWay}"/>
                        </toolkit:DataField>
                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="87"/>
                                <ColumnDefinition Width="116"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            
                            <toolkit:DataField PropertyPath="Subscribed" Label="Subscribe" >
                                <CheckBox IsChecked="{Binding Subscribed, Mode=TwoWay}"/>
                            </toolkit:DataField>
                            <toolkit:DataField PropertyPath="SmartEpFilter" Label="Smart Ep Filter" Grid.Column="1">
                                <CheckBox IsChecked="{Binding SmartEpFilter, Mode=TwoWay}"/>
                            </toolkit:DataField>
                            <Button x:Name="btnUpdate" Content="Update" Grid.Column="2" Width="200"/>
                        </Grid>
                        <toolkit:DataField Label="Items">
                            <ListBox ItemsSource="{Binding FeedItems}" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" HorizontalAlignment="Stretch">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <StackPanel Orientation="Horizontal">
                                                <Image Source="/uTorrentSL;component/Down.PNG" Stretch="None" Margin="0,-10,0,0" Visibility="{Binding InHistory, Converter={StaticResource b2v}}" />
                                                <TextBlock Text="{Binding Name}" Padding="0,0,0,10"/>
                                            </StackPanel>
                                            <TextBlock HorizontalAlignment="Right" Text="{Binding TimeStamp}" Padding="0,0,0,10" Grid.Column="1"/>
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </toolkit:DataField>
                    </StackPanel>
                </DataTemplate>
            </toolkit:DataForm.EditTemplate>
        </toolkit:DataForm>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Button x:Name="btnSave" Content="Save" Command="{Binding SaveFeed}">

            </Button>
            <Button Content="Remove" Grid.Column="1" Command="{Binding RemoveFeed}"/>
        </Grid>
    </Grid>
</UserControl>
